package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.RecruitmenPlan;
import cn.wolfcode.crm.query.RecruitmenPlanQueryObject;
import cn.wolfcode.crm.service.IRecruitmenPlanService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("recruitmenPlan")
public class RecruitmenPlanController {

    @Autowired
    private IRecruitmenPlanService recruitmenPlanService;

    @RequestMapping("index")
    public String index(){
        return "recruitmenPlan/list";
    }

    @ResponseBody
    @RequestMapping("list")
    public PageResult index(RecruitmenPlanQueryObject qo){
        PageResult result = recruitmenPlanService.queryListByQo(qo);
        return result;
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(RecruitmenPlan recruitmenPlan){
        JsonResult result = new JsonResult();
        try {
            recruitmenPlanService.insert(recruitmenPlan);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存出错!");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping("update")
    public JsonResult update(RecruitmenPlan recruitmenPlan){
        JsonResult result = new JsonResult();
        try {
            recruitmenPlanService.updateByPrimaryKey(recruitmenPlan);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("编辑出错!");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping("delete")
    public JsonResult delete(Long id){
        JsonResult result = new JsonResult();
        try {
            if (id!=null){
                recruitmenPlanService.deleteByPrimaryKey(id);
            }
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("编辑出错!");
        }
        return result;
    }

    @ResponseBody
    @RequestMapping("queryRecruitmenPlanByid")
    public RecruitmenPlan queryRecruitmenPlanByid(Long id){
        return recruitmenPlanService.selectByPrimaryKey(id);
    }

    @ResponseBody
    @RequestMapping("queryAllRecruitmenPlan")
    public List<RecruitmenPlan> queryAllRecruitmenPlan(){
        return recruitmenPlanService.selectAll();
    }
}
